package main;

import java.io.IOException;

import compiler.Compiler;

public class Main {

    /*
    private static final int ALLAN = 0;
    private static final int TIAGO = 1;
	
	private static final int USER = TIAGO;
	
	static String[] ifnames = { "/home/allan/college/ICF/eclipse/workspace/awesome-compiler/Compiler/dist/tests/test12", "/home/tiago/workspaceAwesome/awesome-compiler/Compiler/dist/tests/test12" };
    static String[] ofnames = { "/home/allan/Desktop/saida.c", "/home/tiago/CompilerTests/tests/test8.out.c" };
    
    static String ifname = ifnames[USER];
    static String ofname = ofnames[USER];
    */

    public static void main(String[] args) {
    	try {
    		boolean shell = true;
    		
    		if(args.length != 2 && shell) {
    			error("usage: java -jar Compiler.jar <inputfile> <outputfile>");
    		} 
    		
    		String ifname = args[0];
    		String ofname = args[1];
    		
    		if(!ofname.endsWith(".c")) {
    			error("output file must be a .c file");
    		} else {
    			Compiler c = new Compiler();
    			
    			c.compile(ifname, ofname);
    		}
    	} catch (IOException e) {
    		error(e.getMessage());
    	}
    }
    
    /**
     * Shows an error and stops the process
     * @param msg The error message
     */
    private static void error(String msg) {
    	System.err.println(msg);
    	System.exit(1);
    }

}
